.text
    .align 4
    .global begin
    .type begin, function

begin:
    @Bit field manipulation
    ldr r2,=0x23ff4600
    ldr r3,=0x34aa53ff
    mov r0,r2,lsr #24
    Orr r3,r0,r3,lsl #8         @ r3 = ?
        
    @Multiplication by constat
    mov r0,#20
    mov r0,r0,lsl #4			@ r0 = ?
    mov r0,r0,lsl #4			@ r0 = ?
    rsb r0,r0,r0,lsl #4			@ r0 = ?
        
    @multi-precision arithmetic(64 bit)
    ldr r0,=0x40          		@ r0 and r1 hold a 64-bit number,r0 is least significant
    ldr r1,=0x33
    
    ldr r2,=0xffffffff          @ r2 and r3 hold a 64-bit number,r2 is least significant
    ldr r3,=0x45
        
add64:
    adds r0,r0,r2				@ r0 and r1 hold 64-bit sum of the 2 numbers
    adc	 r1,r1,r3				@ what is the sum?
  		
sub64:
    subs r0,r0,r2				@ r0 and r1 hold 64-bit difference of the 2 numbers
    sbc  r1,r1,r3				@ what is the difference ?
		
	@swapping endianness
	@two methods: swapping the order of bytes in a word(the endianness)
		
    ldr r0,=0x12345678			@r0 holds the word to be swapped

byteswap1:
    @This method is best for single word
    eor	r1,r0,r0,ror #16		@r0 = A,B,C,D
    bic r1,r1,#0xff0000
    mov r0,r0,ror #8
    eor r0,r0,r1,lsr #8			@r0 = D,C,B,A
    

    ldr r0,=0x12345678			@r0 holds the word to be swapped

byteswap2:
    @This method is best for swapping the endianness of a large number of words
    mov r2,#0xff
    Orr r2,r2,#0xff0000
    
    and r1,r2,r0
    and r0,r2,r0,ror #24
    orr r0,r0,r1,ror #8
		
    @procedure call and return
    
    mov r0,#0x35
    mov r1,#0x45
    bl addfun
    nop
    
    @conditional execution
    
    mov r0,#0x34
    mov r1,#0xd
    bl  gcd							@ get the Greatest common divisor of r0 and r1
    nop
    
    
    @conditional compare instructions
    @if r0 == 0 || r1 ==1
    @	r2 = r3+r4
    cmp 	r0, #0
    cmpne 	r1,#1
    addeq 	r2,r3,r4
    
    @loop variables
    mov r0,#100

loop:
    nop
    nop
    subs	r0,r0,#1
    bne		loop
    
    
    b stop
    
    @ARM assembler code for the Greatest Common Divisor
    @on entry: r0 holds a number, r1 holds another number
    @on exit: r0 holds the 	Greatest common Divisor of the tow numbers	

gcd:
    cmp r0,r1
    subgt r0,r0,r1
    sublt r1,r1,r0
    bne gcd
    mov pc,lr
		
addfun:									
    @add function
    add r0,r0,r1
    mov pc,lr

stop:
    nop
    b stop
